<%@page import="java.util.*"%>
<%@page import="QRCG.DatabaseManager"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Sign Up Screen</title>

<link href="index.css" rel="stylesheet" type="text/css" />

<script src="datetimepicker_css.js"></script>

</head>

<%@ include file="header.jsp"%>

<%

final int MAX_NICKNAME_LENGTH = 20;
final int MAX_SURNAME_LENGTH = 15;
final int MAX_NAME_LENGTH = 45;
final int MAX_EMAIL_LENGTH = 80;

%>

<body>
<%	if (request.getAttribute("errorMessages") == null){ %>
	<div class="information-text">
		<table align="center">
			<tr>
				<td>Oh you decided to Sign Up! Cool! Let's Begin!</td>
			</tr>

			<tr>
				<td>All you have to do is fill out all the "*"!</td>
			</tr>
		</table>
	</div>
<%	} else {
		String[] errors = request.getAttribute("errorMessages").toString().split("\n");
		for(int i=0;i<errors.length;i++){
			%>	<div class="error-message"><%=errors[i]%> </div><%
		}
	}	%>
	<div id="post-form">
		<form name="Signup" method="post" action="SignupServe">
			<div>
				<table class="post-table">
					<tr>
						<td class="post-label"><b>Nickname*</b></td>
						<td><input class="post-textbox" type="text" name="nickname"
							value="${nickname}" maxlength=<%=MAX_NICKNAME_LENGTH %>/></td>
					</tr>

					<tr>
						<td class="post-label"><b>Name*</b></td>
						<td><input class="post-textbox" type="text" name="name"
							 value="${name}" maxlength=<%=MAX_NAME_LENGTH %>/></td>
					</tr>

					<tr>
						<td class="post-label"><b>Surname*</b></td>
						<td><input class="post-textbox" type="text" name="surname"
							value="${surname}" maxlength=<%=MAX_SURNAME_LENGTH %> /></td>
					</tr>

					<tr>
						<td class="post-label"><b>e-mail*</b></td>
						<td><input class="post-textbox" type="text" name="email"
							 value="${email}" maxlength=<%=MAX_EMAIL_LENGTH %>/></td>
					</tr>

					<tr>
						<td class="post-label"><b>Gender</b></td>
						<td align="left" width="10%">
							<%
								/* TODO(cihat): Keep the values in case of a failed sign up. */
							%> <input type="radio" name="gender" value="0">Female <input
							type="radio" name="gender" value="1">Male
						</td>
					</tr>

					<%
						DatabaseManager conn = new DatabaseManager();
						conn.connect();
						ArrayList<HashMap<String, Object>> LocList = conn.getAllLocations();
						int numberOfLocations = LocList.size();
						System.out.println(numberOfLocations);
					%>
					<tr>
						<td class="post-label"><b>Location</b></td>
						<td><SELECT class="post-selection" name="location">
								<%
									int originalLocationId = -1;
									if (request.getAttribute("location") != null) {
										originalLocationId = Integer.parseInt((String) request.getAttribute("location"));
									}
									for (int i = 0; i < numberOfLocations; i++) {
										HashMap<String, Object> map = (HashMap<String, Object>) LocList.get(i);
										int locationId = ((Integer) map.get("location_id")).intValue();
										String locationName = map.get("location_name").toString();
								%>

								<OPTION value="<%=locationId%>"
									<%if (locationId == originalLocationId) {%> selected="selected"
									<%}%>><%=map.get("location_name")%></OPTION>
								<%
									}
								%>
						</SELECT></td>
					</tr>

					<tr>
						<td class="post-label"><b>Password*</b></td>
						<td><input class="post-textbox" type="password"
							 name="password1" /></td>
					</tr>

					<tr>
						<td class="post-label"><b>Verify Password*</b></td>
						<td><input class="post-textbox" type="password"
							name="password2" /></td>
					</tr>

					<tr>
						<td />
						<td><input id="button-type" type="submit" value="Submit" /></td>
					</tr>
				</table>
			</div>
		</form>
	</div>
</body>
<%@ include file="footer.jsp"%>